<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="./layui/css/layui.css">
    <link rel="stylesheet" href="./css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body style="background-color: white">
<div class="layui-form layuimini-form">
 <div class="layui-form-item">
 <input type="hidden" name="id" value="${user.id }">
  </div>

    <div class="layui-form-item">
        <label class="layui-form-label required">用户名</label>
        <div class="layui-input-block">
            <input type="text" name="userName" lay-verify="required" value="${user.userName}" lay-reqtext="用户名不能为空" placeholder="请输入用户名" value="" class="layui-input" autocomplete="off">
            <tip>填写自己管理账号的名称</tip>
        </div>
    </div>
    
    <div class="layui-form-item">
        <label class="layui-form-label required">手机</label>
        <div class="layui-input-block">
            <input type="number" name="phone" lay-verify="required|phone" value="${user.phone}" lay-reqtext="手机不能为空" placeholder="请输入手机" value="$" class="layui-input" autocomplete="off">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">邮箱</label>
        <div class="layui-input-block">
            <input type="email" name="email" value="${user.email}" placeholder="请输入邮箱" value="" class="layui-input" autocomplete="off">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">账号类型</label>
        <div class="layui-input-block">
            <select name="role" lay-verify="required" lay-filter="selFilter" id="role">
                <option value=""></option>
                <option value="0">普通用户</option>
                <option value="1">管理员</option>
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">是否禁用</label>
        <div class="layui-input-block">
            <select name="state" lay-verify="required" lay-filter="selFilter" id="state">
                <option value=""></option>
                <option value="0">是</option>
                <option value="1">否</option>
            </select>
        </div>
    </div>
   
<!--     <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">备注信息</label>
        <div class="layui-input-block">
            <textarea name="remark" class="layui-textarea" placeholder="请输入备注信息" autocomplete="off"></textarea>
        </div>
    </div>
 -->
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>

</div>

<script src="./layui/layui.js"></script>
<script>
    layui.use(['form'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$;

        //渲染默认
        $("#role").val(${user.role});
        $("#state").val(${user.state});
        form.render();

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            var index = layer.alert(JSON.stringify(data.field), {
                title: '最终的提交信息'
            }, function () {

                // 关闭弹出层
                /* layer.close(index);

                var iframeIndex = parent.layer.getFrameIndex(window.name);
                parent.layer.close(iframeIndex); */
                
                $.ajax({
                    url:'./updateUser',
                    type:'post',
                    data:{data:JSON.stringify(data.field)},
                    
                   /*  beforeSend:function () {
                        this.layerIndex = layer.load(0, { shade: [0.5, '#393D49'] });
                    }, */
                    success:function(data){
                        if(data.status == 'error'){
                            layer.msg("失败",{icon: 5});//失败的表情
                            o.removeClass('layui-btn-disabled');
                            return;
                        }else{
                            layer.msg("成功", {
                                icon: 6,//成功的表情
                                time: 2000 //1秒关闭（如果不配置，默认是3秒）
                            }, function(){
                            layer.close(index);
                      		var iframeIndex = parent.layer.getFrameIndex(window.name);
                      		parent.layer.close(iframeIndex);  
                      		window.parent.location.reload();
                            });
                        }
                    },
                    error:function(e){
                    	 layer.msg("失败",
                    			 {icon: 5},
                    			 function(){
                             location.reload();
                         });//失败的表情
                    	console.log(e);
                    },
                    
                    complete: function () {

                        //window.parent.location.reload();
                        
                    },
                });
	

            });

            return false;
        });

    });
</script>
</body>
</html>